package v2

import (
	rpcv1 "gluenet/internal/agent/api/rpc/v1"
	corev1 "gluenet/pkg/agent/types"
	"gluenet/pkg/agent/v2/rpc"
)

type LogGetter interface {
	Log() GluenetLogInterface
}

type GluenetLogInterface interface {
	LogCounts(logCountsReq *corev1.LogCounts) (result []map[string]interface{}, err error)
	LogInfo(logInfoReq *corev1.LogInfo) (result []map[string]interface{}, err error)
}

type gluenetLog struct {
	client rpc.Interface
}

func newGluenetLog(c *CoreClient) *gluenetLog {
	return &gluenetLog{
		client: c.RPCClient(),
	}
}

func (c *gluenetLog) LogCounts(logCountsReq *corev1.LogCounts) (result []map[string]interface{}, err error) {
	err = c.client.Invoke().
		Api(rpcv1.LogCounts).
		Spec(*logCountsReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetLog) LogInfo(logInfoReq *corev1.LogInfo) (result []map[string]interface{}, err error) {
	err = c.client.Invoke().
		Api(rpcv1.LogInfo).
		Spec(*logInfoReq).
		Do().
		Into(&result)
	return
}
